<?php

namespace App\Web\Model;

use App\Facades\UrlCrypt;
use App\Service\Engine\ResumeEngine;

/**
 * 找简历业务逻辑
 * Class ResumeSearch
 * @package App\Web\Model
 */
Class ResumeSearch extends Model {

    /**
     * 简历搜索
     * @param $params
     * @param $pageNum
     * @param $perPageCount
     * @return array
     */
    public function getResumeList($oprId, $params, $pageNum, $perPageCount) {
        $resumeEngine = new ResumeEngine();
        $engineResult = $resumeEngine->search($params, $pageNum, $perPageCount);

        $searchResumeIds = array_slice($engineResult['mgrIDArr'], ($engineResult['pageNum'] - $engineResult['lastCallEnginePageNum']) * $perPageCount, $perPageCount);

        $resumeList = [];
        if (!empty($searchResumeIds)) {
            $managerModel = new Manager();
            $resumeList = $managerModel->getManagerListByResumeId($searchResumeIds);
            $resumeList = $managerModel->chkDownload($oprId, $resumeList);
            $resumeList = $managerModel->chkRead($oprId, $resumeList);
            $resumeList = $managerModel->chkInCase($resumeList);

            $resumeidArr = array_column($resumeList, 'resumeid');
            $engineResult['listkey'] = implode(",", $resumeidArr);
            $engineResult['listtoken'] = UrlCrypt::generateToken($resumeidArr);
        }
        $engineResult['resumelist'] = $resumeList;
        if ($engineResult['callresult'] == 2) {
            $engineResult['allMgrCount'] = count($resumeList);
            $engineResult['mgrCount'] = count($resumeList);
        }

        return $engineResult;
    }
}